<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	    		xmlns:ui="http://java.sun.com/jsf/facelets"
	  			xmlns:h="http://java.sun.com/jsf/html"
	  			xmlns:f="http://java.sun.com/jsf/core"
	  			xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:a="http://richfaces.org/a4j"
                xmlns:rich="http://richfaces.org/rich"
				template="template.xhtml">

<ui:define name="page-name">
	<h:outputText value="Ativos"/>
</ui:define>

<!-- content -->
<ui:define name="content">

<div class="section">
	<h:form id="ativos123">
		<s:button
			id="voltar"
			value="Voltar"
			view="/ativos.xhtml"
			propagation="end"/>
	</h:form>
</div>

<div class="section">
<h:form id="criarCarteira">

	<h:commandButton action="#{ativoHome.importarSeries}" value="Atualizar Series" />
	<rich:spacer width="7"/>
	<h:commandButton action="#{ativoHome.cargaInicial}" value="Carga Inicial" />
	
  	<rich:panel>
	  	<f:facet name="header">
	  		<h:outputText value="Informacoes do Ativo"/>
	  	</f:facet>
		<h:panelGrid columns="2">
		
			<h:outputText value="id" />
			<h:outputText value="#{ativoHome.instance.id}" />

			<h:outputText value="Data de Carga Inicial" />
			<rich:calendar value="#{ativoHome.instance.dataCargaInicial}"
                        datePattern="dd/MM/yyyy"
                        showApplyButton="true"
						cellWidth="24px"
						cellHeight="22px"
						style="width:200px"
						enableManualInput="false"/>
		
			<h:outputText value="Ultima Atualizacao" />	
			<h:outputText value="#{ativoHome.instance.ultimaAtualizacao}">
				<s:convertDateTime pattern="dd/MM/yyyy HH:mm:ss"/>
			</h:outputText>
		
			<h:outputText value="simbolo" />
			<h:inputText value="#{ativoHome.instance.simbolo}" />
			
			<h:outputText value="nome" />
			<h:inputText value="#{ativoHome.instance.nome}" />
			
			<h:outputText value="series" />
			<h:outputText value="#{empty ativoHome.series ? 'nenhuma' : ativoHome.series.size}" />
		</h:panelGrid>
		
		<h:commandButton action="#{ativoHome.update}" value="Atualizar" />
		<rich:spacer width="7"/>
		<h:commandButton action="#{ativoHome.remove}" value="Remover" disabled="#{not empty ativoHome.carteiras}"/>
		
	</rich:panel>
	<rich:spacer height="7"/>
	<rich:panel>
	  	<f:facet name="header">
	  		<h:outputText value="Amostra de Series"/>
	  	</f:facet>
	  	<h:outputText id="semSeriesMessage" value="Sem Series Cadastradas" rendered="#{empty ativoHome.series}"/>
	  	<rich:dataTable id="series"
			value="#{ativoHome.series}" 
	  		var="serie"
			rendered="#{not empty ativoHome.series}" rows="15">
	        <rich:column id="data">
	            <f:facet name="header"><h:outputText  value="data" /></f:facet>
	            <h:outputText value="#{serie.data}">
					<s:convertDateTime pattern="dd/MM/yyyy"/>
				</h:outputText>
	        </rich:column>
	        <rich:column id="open">
	            <f:facet name="header"><h:outputText  value="open" /></f:facet>
	            <h:outputText value="#{serie.open}" />
	        </rich:column>
	        <rich:column id="high">
	            <f:facet name="header"><h:outputText  value="high" /></f:facet>
	            <h:outputText value="#{serie.high}" />
	        </rich:column>
	        <rich:column id="low">
	            <f:facet name="header"><h:outputText  value="low" /></f:facet>
	            <h:outputText value="#{serie.low}" />
	        </rich:column>
	        <rich:column id="close">
	            <f:facet name="header"><h:outputText  value="close" /></f:facet>
	            <h:outputText value="#{serie.close}" />
	        </rich:column>
	        <rich:column id="Vol">
	            <f:facet name="header"><h:outputText  value="Vol" /></f:facet>
	            <h:outputText value="#{serie.volume}" />
	        </rich:column>
	    </rich:dataTable>
    </rich:panel>
	<rich:spacer height="7"/>
	<rich:panel>
	  	<f:facet name="header">
	  		<h:outputText value="Carteiras que utilizam esse ativo"/>
	  	</f:facet>
	  	<h:outputText id="semCarteirasMessage" value="Nenhuma Carteira utiliza esse ativo" rendered="#{empty ativoHome.carteiras}"/>
        <rich:dataList 
	        var="carteira"
	        value="#{ativoHome.carteiras}"
			rows="10"
	        rendered="#{not empty ativoHome.carteiras}">
            <h:outputText value="#{carteira.nome}" /><br/>
        </rich:dataList>
        <h:outputText value="Ativos utilizados por carteiras nao podem ser removidos" rendered="#{not empty ativoHome.carteiras}"/>
    </rich:panel>

	
	
</h:form>
</div>

</ui:define>

</ui:composition>
